/*
 * @lc app=leetcode.cn id=111 lang=java
 *
 * [111] 二叉树的最小深度
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
// class TreeNode {
//          int val;
//          TreeNode left;
//          TreeNode right;
//          TreeNode() {}
//          TreeNode(int val) { this.val = val; }
//          TreeNode(int val, TreeNode left, TreeNode right) {
//              this.val = val;
//             this.left = left;
//              this.right = right;
//          }
//      }
class Solution {
    public int minDepth(TreeNode root) {
        if (root==null) {
            return 0;
            
        }
        return plus(root, 0);        
    }
    int plus(TreeNode root ,int deepth){
        if (root==null) {
            return deepth;
            
        }
        if (root.left==null&&root.right==null) {
            return deepth+1;
        }
        if (root.right==null) {
            return plus(root.left, deepth+1);
            
        }
        if (root.left==null) {
            return plus(root.right, deepth+1);
        }
        return Math.min(plus(root.left, deepth+1), plus(root.right, deepth+1));
    }
}
// @lc code=end

